# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=raspberrypi
pkgver=0.20190416
_commitid=ff2bd4552145e8dc190276d8fbdbadc7e8e0da78
pkgrel=2
pkgdesc="Raspberry Pi support tools"
url="https://github.com/raspberrypi/userland"
arch="armhf armv7 aarch64"
license="BSD-3-Clause"
depends=""
depends_dev="linux-headers raspberrypi-static raspberrypi-libs"
makedepends="cmake $depends_dev"
install=""
options="!fhs !check"
subpackages="$pkgname-dev $pkgname-static $pkgname-libs $pkgname-openrc"
source="raspberrypi-$pkgver.tar.gz::https://github.com/raspberrypi/userland/archive/$_commitid.tar.gz
	"

builddir="$srcdir"/userland-$_commitid

prepare() {
	default_prepare
	sed -i 's/ bash / sh /g' host_applications/linux/apps/raspicam/CMakeLists.txt
}

build() {
	cd "$builddir"
	case "$CARCH" in
		arm*) local ARM64=off;;
		aarch64) local ARM64=on;;
	esac
	cmake -DCMAKE_C_FLAGS="$CFLAGS -D_GNU_SOURCE" \
		-DARM64=$ARM64 \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_RPATH=/opt/vc/lib \
		-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--no-as-needed" \
		$_sourcedir
	make
}

package() {
	cd "$builddir"
	make install DESTDIR="$pkgdir"

	# nuke the unwanted stuff
	rm -rf "$pkgdir"/opt/vc/src
	mv "$pkgdir"/opt/vc/etc "$pkgdir"
}

static() {
	pkgdesc="Static files for $pkgname"

	mkdir -p "$subpkgdir"/opt/vc/lib
	mv "$pkgdir"/opt/vc/lib/*.a "$subpkgdir"/opt/vc/lib
}

libs() {
	pkgdesc="Raspberry Pi support libraries"

	mkdir -p "$subpkgdir"/opt/vc/lib
	mv "$pkgdir"/opt/vc/lib/* "$subpkgdir"/opt/vc/lib
}

sha512sums="dad48bd88d11a3f6807250275950235122bf5f35c47c5891f4e2c40964adbf69de6dbc014cea561540e516bed369257fc134a0114b9bdfa6e6a689a48bfd9f40  raspberrypi-0.20190416.tar.gz"
